#include <iostream>
#include "Sender.h"
#include "Receiver.h"
using namespace std;

int main()
{
  Sender *sender = new Sender;
  sender->notify();
  printf("before connect\n");

  Receiver *receiver = new Receiver;
  GObject::connect(sender, sender->selected, receiver, &Receiver::slotSelected);
  printf("after connect\n");
  sender->notify();

  GObject::disconnect(sender, sender->selected, receiver, &Receiver::slotSelected);
  printf("after disconnect\n");
  sender->notify();

  //请看如下这段代码，这里解释了为什么Sender和Receiver需要继承于GObject。
  //Receiver对象被销毁后，Sender对象与Receiver对象之间的依赖会自动被解除。
  //事实上，如果你根本不在意Receiver被销毁后的情形，那么你当然可以不用继承于GObject。
  printf("re-connected, but delete receiver\n");
  GObject::connect(sender, sender->selected, receiver, &Receiver::slotSelected);
  delete receiver;
  sender->notify();

  return 0;
}
